//
//  JCTabView.swift
//  JCTest3
//
//  Created by Chen on 12/10/2022.
//

import Cocoa

// 第三方https://github.com/shinyfrog/SFTabView
class JCTabView: JCBaseBottomView {
    
    private lazy var tabView: NSTabView = {
        let tabView = NSTabView(frame: NSRect(x: 12, y: 12, width: 600, height: 100))
//        tabView.delegate = self
//        tabView.tabPosition = .top
        
        return tabView
    }()

    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect)

        // Drawing code here.
        self.createTabViews()
        self.setDifferentStyleTab()
    }
    
}

extension JCTabView {
    
    func createTabViews() {
        
        self.addSubview(self.tabView)
        
        // 创建items
        let firstVc = JCTabFirstController()
        let secondVc = JCTabSecondController()
        
//        let item1 = NSTabViewItem.init(viewController: firstVc)
        let item1 = NSTabViewItem.init()
        let item2 = NSTabViewItem.init(viewController: secondVc)
        
        item1.label = "First"
        item1.toolTip = "First Controller"
        item1.image = NSImage(named: "dish_008")
        
        item2.label = "Second"
        
        self.tabView.addTabViewItem(item1)
        self.tabView.addTabViewItem(item2)
        
        
    }
    
    func setDifferentStyleTab() {
        
        // NSTabViewController
//        let tab11 = NSTabViewController()
        
        let tab1 = NSTabView(frame: NSRect(x: 12, y: 140, width: 600, height: 100))
        self.addSubview(tab1)
//        tab1.tabViewBorderType = .line
        tab1.tabViewBorderType = .none
        
        let tab1Item1 = NSTabViewItem()
        let tab1Item2 = NSTabViewItem()
        let tab1Item3 = NSTabViewItem()
        tab1Item1.label = "tab1Item1"
        tab1Item2.label = "tab1Item2"
        tab1Item3.label = "tab1Item3"
        
        tab1.addTabViewItem(tab1Item1)
        tab1.addTabViewItem(tab1Item2)
        tab1.addTabViewItem(tab1Item3)
        
        let tab2 = NSTabView(frame: NSRect(x: 12, y: 270, width: 600, height: 100))
        self.addSubview(tab2)
//        tab1.tabViewBorderType = .line
        tab2.tabViewBorderType = .line
        tab2.tabPosition = .bottom
        tab2.font = NSFont.boldSystemFont(ofSize: 24)
        
        let tab2Item1 = NSTabViewItem()
        let tab2Item2 = NSTabViewItem()
        let tab2Item3 = NSTabViewItem()
        tab2Item1.label = "tab2Item1"
        tab2Item2.label = "tab2Item2"
        tab2Item3.label = "tab2Item3"
        
        tab2.addTabViewItem(tab2Item1)
        tab2.addTabViewItem(tab2Item2)
        tab2.addTabViewItem(tab2Item3)
        
        // 自定义tabitem
        let tab3 = NSTabView(frame: NSRect(x: 12, y: 400, width: 600, height: 100))
        self.addSubview(tab3)
//        tab1.tabViewBorderType = .line
        tab3.tabViewBorderType = .line
        tab3.tabPosition = .bottom
        tab3.drawsBackground = false
        
        let tab3Item1 = NSTabViewItem()
        let tab3Item2 = NSTabViewItem()
        let tab3Item3 = NSTabViewItem()
        tab3Item1.label = "tab3Item1"
        tab3Item2.label = "tab3Item1"
        tab3Item3.label = "tab3Item3"
        tab3Item1.color = .yellow
        
        tab3.addTabViewItem(tab3Item1)
        tab3.addTabViewItem(tab3Item2)
        tab3.addTabViewItem(tab3Item3)
        
        // 自定义一个视图给tab3Item1
        let cusButton = NSButton()
        cusButton.title = "custom"
        cusButton.setupViewBackgroundColor(color: .yellow)
        tab3Item1.view = cusButton // 这个是空白内容区
        
    }
}

class JCTabItem: JCBaseView {
    
    public var title: String?
    public var titleColor: NSColor?
    
    private lazy var showButton: NSButton = {
        let showButton = NSButton()
        return showButton
    }()
    
    
}
